﻿using Manon.Admin.Web.ApplicationCore.Dtos;
using Manon.Admin.Web.ApplicationCore.Dtos.Member;
using Manon.Admin.Web.ApplicationCore.Interfaces;
using Manon.Core.IOC;
using Manon.Core.Commons;
using Manon.Repository.Collections;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Manon.Admin.Web.Controllers
{
    public class MemberController : Controller
    {


        #region 会员管理
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult Edit()
        {
            return View();
        }

        [Authorize]
        [HttpGet]
        public async Task<List<GetMemberLevelOutput>> GetMemberLeveldList()
        {

            var memberService = Resolver.GetService<IMemberService>();
            var result = await memberService.GetMemberLevelList();

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<IPagedList<GetMemberOutput>> GetMemberPagedList([FromBody] GetMemberPagedListInput Input)
        {

            var memberService = Resolver.GetService<IMemberService>();
            var result = await memberService.GetMemberPagedList(Input);

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> SaveMember([FromBody] SaveMemberInput Input)
        {
            var memberService = Resolver.GetService<IMemberService>();
            var result = await memberService.SaveMember(Input);
            return result;
        }
        [Authorize]
        [HttpGet]
        public async Task<GetMemberOutput> GetMember(int Id)
        {

            var memberService = Resolver.GetService<IMemberService>();
            var result = await memberService.GetMember(Id);
            return result;
        }
        [Authorize]
        [HttpPost]
        public async Task<Result> SetMemberEnabled(int Id, bool Enabled)
        {

            var memberService = Resolver.GetService<IMemberService>();
            var result = await memberService.SetMemberEnabled(Id, Enabled);
            return result;
        }

        #endregion




        #region 会员等级
        public IActionResult Level()
        {
            return View();
        }

        public IActionResult LevelEdit()
        {
            return View();
        }


        [Authorize]
        [HttpPost]
        public async Task<IPagedList<GetMemberLevelOutput>> GetMemberLevelPagedList([FromBody] GetMemberLevelPagedListInput Input)
        {

            var memberService = Resolver.GetService<IMemberService>();
            var result = await memberService.GetMemberLevelPagedList(Input);

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> SaveMemberLevel([FromBody] SaveMemberLevelInput Input)
        {
            var memberService = Resolver.GetService<IMemberService>();
            var result = await memberService.SaveMemberLevel(Input);
            return result;
        }
        [Authorize]
        [HttpGet]
        public async Task<GetMemberLevelOutput> GetMemberLevel(int Id)
        {

            var memberService = Resolver.GetService<IMemberService>();
            var result = await memberService.GetMemberLevel(Id);
            return result;
        }
        [Authorize]
        [HttpPost]
        public async Task<Result> SetMemberLevelEnabled(int Id, bool Enabled)
        {

            var memberService = Resolver.GetService<IMemberService>();
            var result = await memberService.SetMemberLevelEnabled(Id, Enabled);
            return result;
        }
        #endregion
    }
}
